//
//  BDDisplayLocationViewController.m
//  BadBoy
//
//  Created by wen on 2017/5/9.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDDisplayLocationViewController.h"
#import <AMap2DMap-NO-IDFA/MAMapKit/MAMapKit.h>

@interface BDDisplayLocationViewController ()<MAMapViewDelegate>

@property (nonatomic, assign) double longitue;
@property (nonatomic, assign) double latitue;
@property (nonatomic, strong) NSString *address;

@property (nonatomic, strong) MAMapView *mapView;

@property (nonatomic, strong) UIButton *backButton;
@property (nonatomic, strong) UILabel *bottomLabel;
@end

@implementation BDDisplayLocationViewController

- (instancetype)initWithLongitue:(double)longitue latitue:(double)latitue address:(NSString *)address{
    if (self = [super init]) {
        self.longitue = longitue;
        self.latitue = latitue;
        self.address = address;
    }
    
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.mapView.centerCoordinate = CLLocationCoordinate2DMake(self.latitue, self.longitue);
    
    MAPointAnnotation *a1 = [[MAPointAnnotation alloc] init];
    a1.coordinate = self.mapView.centerCoordinate;
    [self.mapView addAnnotations:@[a1]];
    
    self.bottomLabel.text = self.address;
    
    [[self.backButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        [self.navigationController popViewControllerAnimated:YES];
    }];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (MAAnnotationView*)mapView:(MAMapView *)mapView viewForAnnotation:(id <MAAnnotation>)annotation {
    if ([annotation isKindOfClass:[MAPointAnnotation class]])
    {
        static NSString *pointReuseIndetifier = @"pointReuseIndetifier";
        MAAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];
        if (annotationView == nil) {
            annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndetifier];
        }
        annotationView.canShowCallout               = NO;        //弹出小视图
        annotationView.image = [UIImage imageNamed:[NSString stringWithFormat:@"location_datouzhen"]];
        
        return annotationView;
    }
    return nil;
}

- (MAMapView *)mapView{
    if (!_mapView) {
        self.mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth, kBDScreenHeight - 40)];
        //        _mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        _mapView.delegate = self;
        _mapView.centerCoordinate = CLLocationCoordinate2DMake(23.117055306224895, 113.2759952545166);
        _mapView.showsUserLocation = NO;
        _mapView.showsCompass = NO;
        _mapView.showsScale = NO;
        MAUserLocationRepresentation *locationRepresntation = [[MAUserLocationRepresentation alloc] init];
        locationRepresntation.showsAccuracyRing = YES;
        [_mapView updateUserLocationRepresentation:locationRepresntation];
        _mapView.zoomLevel = 14.2;
        _mapView.minZoomLevel = 5;
        _mapView.maxZoomLevel = 20;
        [self.view addSubview:_mapView];
    }
    return _mapView;
}

- (UILabel *)bottomLabel{
    if (!_bottomLabel) {
        self.bottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth - 30, 40)];
        _bottomLabel.font = [UIFont systemFontOfSize:17];
        _bottomLabel.textColor = [UIColor colorWithHexString:@"#4c4c4c"];
        
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth, 40)];
        view.backgroundColor = [UIColor whiteColor];
        view.bottom = kBDScreenHeight;
        [self.view addSubview:view];
        
        _bottomLabel.centerX = kBDScreenWidth / 2.0;
        [view addSubview:_bottomLabel];
    }
    return _bottomLabel;
}

- (UIButton *)backButton{
    if (!_backButton) {
        self.backButton = [[UIButton alloc]initWithFrame:CGRectMake(5, 0, 30, 30)];
        _backButton.centerY = kBDStatusBarHeight + kBDNavBarHeight / 2.0;
        [_backButton setImage:[UIImage imageNamed:@"call_locationBack"] forState:UIControlStateNormal];
//        _backButton.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
        [self.view addSubview:_backButton];
    }
    return _backButton;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
